package com.gopay.webtest.controller.cloud;

import java.util.Date;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.gopay.webtest.controller.base.BaseController;
import com.gopay.webtest.handler.cloud.TransCloudSignHandler;
import com.gopay.webtest.util.DateUtils;
import com.gopay.webtest.vo.cloud.Cloud0617Vo;
import com.gopay.webtest.xml.XmlDao;
/**
 * 
 * @ClassName: CloudRefundController 
 * @Description: 云账户退款接口Controller
 * @author jiaoshuai 
 * @date 2016年9月21日 下午5:22:36
 */
@Controller
@RequestMapping("/cloud/refund")
public class CloudRefundController extends BaseController {

    
    @Resource(name = "xmlDao")
    private XmlDao xmlDao;
    
    @Resource(name="transCloudSignHandler")
    private TransCloudSignHandler transCloudSignHandler;
    
    
    @RequestMapping("/refundApply")
    public ModelAndView chargeApply() {
        ModelAndView mv = new ModelAndView();

        
    try {
            this.logger.error("^^^^^^^^^^^^^^^^^云平台账户  退款  申请页面初始化成功^^^^^^^^^^^^^^^^^");
            
             Map<String, String> map = xmlDao.readData4Map("cloud_apply", "refund");

             map.put("tranDateTime", DateUtils.format(new Date(), "yyyyMMddHHmmss"));
             map.put("merOrderNum", System.currentTimeMillis()+"");
             mv = new ModelAndView("cloud.refund.apply");
             mv.addObject("config", map);
            
        } catch (Exception e) {
            logger.error("跳转页面", e);
        }

        return mv;
    }
    
    
    @RequestMapping("/doRefundSubmit")
    public ModelAndView doCharge(@ModelAttribute Cloud0617Vo req){
         ModelAndView mv = new ModelAndView();

         try {
             this.logger.error("^^^^^^^^^^^^^^^^^云平台账户 退款 申请页面签名成功^^^^^^^^^^^^^^^^^");
             // 签名
             transCloudSignHandler.sign(req.getTranCode()+"_"+req.getVersion(), "signType", "signValue", req, getRequest());

             mv.setViewName("cloud.refund.doApply");
             mv.addObject("applyVo", req);
         } catch (Exception e) {
             logger.error("执行申请", e);
         }
         return mv;
    }
}
